#ifndef __EVENT_H__
#define __EVENT_H__

#include <stdint.h>
#include <stdbool.h>
#include <pthread.h>
#include "queue.h"
#include "radar_protocol.h"

#define OBJ_STATIC_QUEUE_SIZE 20
#define OBSTACLE_SEGMENT      100

#define SEGMENT_COUNT  10                           // 分成 10 段
#define SEGMENT_LENGTH 10000                        // 总长 1000m
#define INTERVAL_MIN   2                            // 每个统计槽 2 分钟
#define WINDOW_MIN     10                           // 滑动窗口 10 分钟
#define WINDOW_SLOTS   (WINDOW_MIN / INTERVAL_MIN)  // 5 个槽

#define LC_THRESHOLD 5  // 变道阈值，单位次

typedef struct {
    int32_t time;
    int16_t count;
} change_lane_statistic_t;

typedef struct {
    Queue_t *incoming_obj_static_queue;
    Queue_t *outgoing_obj_static_queue;

    int incoming_last_seen_time[MAX_ROWS][OBSTACLE_SEGMENT];
    int outgoing_last_seen_time[MAX_ROWS][OBSTACLE_SEGMENT];

    bool incoming_report[MAX_ROWS][OBSTACLE_SEGMENT];
    bool outgoing_report[MAX_ROWS][OBSTACLE_SEGMENT];

    int incoming_seen_range[2];
    int outgoing_seen_range[2];

    Queue_t *incoming_change_lane_static_queue[SEGMENT_COUNT];
    Queue_t *outgoing_change_lane_static_queue[SEGMENT_COUNT];

    Queue_t *sstk_event_queue;  // 用于 SSTK 协议的事件队列
} event_manager_t;

pthread_t start_event_server(void);
void update_obj_statistics(radar_obj_info_t *radar_info, int8_t dev_type);
int get_obj_lane(radar_obj_info_t *radar_info, uint8_t dev_type);
void process_lane_change(int position_meter, int8_t dev_type);
#endif  // !__EVENT_H__
